package com.chen.auth.domain.service.impl;

import com.chen.auth.common.enums.IsDeletedFlagEnum;
import com.chen.auth.domain.entity.AuthRolePermissionBO;
import com.chen.auth.domain.service.AuthRolePermissionDomainService;
import com.chen.auth.infra.basic.entity.AuthRolePermission;
import com.chen.auth.infra.basic.service.AuthRolePermissionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

@Service
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {


    @Resource
    private AuthRolePermissionService authRolePermissionService;


    /**
     * 新增角色权限关联关系
     */
    @Override
    public Boolean add(AuthRolePermissionBO authRolePermissionBO) {
        List<AuthRolePermission> rolePermissionList = new LinkedList<>();
        //获取角色id
        Long roleId = authRolePermissionBO.getRoleId();
        //获取新增的权限的id
        authRolePermissionBO.getPermissionIdList().forEach(permissionId->{
            AuthRolePermission authRolePermission = new AuthRolePermission();
            //设置角色id
            authRolePermission.setRoleId(roleId);
            //设置权限id
            authRolePermission.setPermissionId(permissionId);
            //设置删除状态
            authRolePermission.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
            rolePermissionList.add(authRolePermission);
        });
       int count =  authRolePermissionService.batchInsert(rolePermissionList);
       return count >0;
    }
}
